class Student{
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class TestDemo1 {

    public static void main(String[] args) {
        //分割字符串，有“.”、“|”、“*”等符号作为分隔符时需要加“\\”
        //如果是“\”，那么就需要加上"\\\"。
        String str1 = "www.qucixa.com";
        String[] str2 = str1.split("\\.");
        for (String str : str2) {
            System.out.println(str);
        }
        System.out.println("===================");
        //去掉两边空格
        String str3 = "    abc  defg   ";
        String str4 = str3.trim();
        System.out.println(str3);
        System.out.println(str4);
        String str5 = new String();
    }
    public static void main6(String[] args) {
        //字符串替换
        String str1 = "Hello World";
        String str2 = str1.replace("ll","ee");
        String str3 = str1.replaceFirst("o","M");
        String str4 = str1.replaceAll("o","M");
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);
    }
    public static void main5(String[] args) {
        //大小写转化
        String str1 = "hello";
        String str2 = "WORLD";
        System.out.println(str1);
        System.out.println(str2);
        String str3 = str1.toUpperCase();
        String str4 = str2.toLowerCase();
        System.out.println("=================");
        System.out.println(str3);
        System.out.println(str4);
        //字符串格式化
        String str5 = String.format("%d-%d-%d",2025,3,24);
        System.out.println(str5);
    }

    public static void main4(String[] args) {
        //字符串转为其他类型数据
        int ret1 = Integer.parseInt("100100",2);//以后面数字的进制返回字符串对应的十进制数
        int ret2 = Integer.parseInt("1234");
        double ret3 = Double.parseDouble("1234.56");
        System.out.println(ret1);
        System.out.println(ret2);
        System.out.println(ret3);
    }
    public static void main3(String[] args) {

        String str = String.valueOf(new Student("zhangsan",15));
        //其他类型数据转换为字符串
        char[] array = new char[]{'a','b','c','d','e'};
        String str1 = String.valueOf(1234);
        String str2 = String.valueOf(123.45);
        String str3 = String.valueOf(true);
        String str4 = String.copyValueOf(array);
        System.out.println(str);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);
    }

    public static void main2(String[] args) {
        //在字符串中查找对应字符或字符串所在的位置，可以从指定位置开始查找
        String str1 = "Hello World";
        int i = str1.indexOf("ll");
        int j = str1.indexOf('e');
        System.out.println(i);
        System.out.println(j);
        int m = str1.indexOf('o',5);
        System.out.println(m);
        int n = str1.lastIndexOf("ll",5);
        System.out.println(n);
    }

    public static void main1(String[] args) {
        String str1 = "Hello World";
        String str2 = "Hello World";
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
        System.out.println("=================");
        String str3 = new String("Hello World");
        String str4 = new String("Hello World");
        System.out.println(str3 == str4);
        System.out.println(str3.equals(str4));
        System.out.println(str1.equals(str3));
        char a = str1.charAt(2);
        System.out.println(a);

    }
}
